import requests
from bs4 import BeautifulSoup

def get_table_data(url):
    # 发送HTTP请求获取网页内容
    response = requests.get(url)
    print(response.text)
    response.raise_for_status()  # 确保请求成功

    # 使用BeautifulSoup解析HTML内容
    soup = BeautifulSoup(response.text, 'html.parser')

    # 找到表格
    table = soup.find('table', {'id': 'simple-table'})

    # 初始化一个列表来存储表格数据
    data = []

    # 遍历表格的每一行
    for row in table.find_all('tr'):
        columns = row.find_all('td')
        if columns:
            # 获取每列的文本内容
            file_name = columns[0].text.strip()
            file_size = columns[1].text.strip()
            download_link = columns[2].find('a', title='下载')['onclick'].split("'")[1]  # 获取下载链接
            copy_link = columns[2].find('a', title='复制链接')['onclick'].split("'")[1]  # 获取复制链接

            # 将每行的数据存储为字典
            row_data = {
                'file_name': file_name,
                'file_size': file_size,
                'download_link': download_link,
                'copy_link': copy_link
            }
            data.append(row_data)

    return data

# 示例URL
url = 'https://diagnosis.kion-cn.com/lindediagnosis/writePacket/todownload.do?id=111'
table_data = get_table_data(url)
for item in table_data:
    print(item)
